#include "StdAfx.h"
#include "Card.h"
#include "GameLogic.h"

CCard::CCard(void)
{
	m_nCardData = 0;  
	m_nShowType = 0;
	m_bUp = FALSE;
	m_bSelect = FALSE;
	m_bHover = FALSE;
}

CCard::~CCard(void)
{
}

int CCard::GetColor()
{
	return CGameLogic::GetCardColor(m_nCardData);
}

int CCard::GetValue()
{
	return CGameLogic::GetCardValue(m_nCardData);
}

void CCard::Render(CDC *pDC)
{
	if(!IsVisible()) return;
	if(!g_imgCard.IsValid()) return;

	int nCardWidth = g_imgCard.GetWidth() / CardImage_Col_Count;
	int nCardHeight = g_imgCard.GetHeight() / CardImage_Row_Count;

    int nRow = (m_nCardData - 1) / Per_Color_Card_Count;
	int nCol = (m_nCardData - 1) % Per_Color_Card_Count;
	if(m_nShowType == Card_ShowType_Background)
	{
        nRow = 4;
		nCol = 4;
	}
	int nSrcLeft = nCol * nCardWidth;
	int nSrcTop = nRow * nCardHeight;

	CRect rcDst(m_nCurPosX, m_nCurPosY, m_nCurPosX + m_nWidth, m_nCurPosY + m_nHeight);
	CRect rcSrc(nCol * nCardWidth, nRow * nCardHeight, nCol * nCardWidth + nCardWidth, nRow * nCardHeight + nCardHeight);

    g_imgCard.DrawPart(pDC->m_hDC, rcDst, rcSrc);

	if(m_bSelect)
	{
		CRect rcSrc((CardImage_Col_Count - 1) * nCardWidth, (CardImage_Row_Count - 1) * nCardHeight, CardImage_Col_Count * nCardWidth, CardImage_Row_Count * nCardHeight);
		g_imgCard.DrawPart(pDC->m_hDC, rcDst, rcSrc);
	}
}

void CCard::RenderSmall(CDC *pDC)
{
	if(!IsVisible()) return;
	if(!g_imgCard.IsValid()) return;

	int nCardWidth = g_imgCard.GetWidth() / CardImage_Col_Count;
	int nCardHeight = g_imgCard.GetHeight() / CardImage_Row_Count;

	int nRow = (m_nCardData - 1) / Per_Color_Card_Count;
	int nCol = (m_nCardData - 1) % Per_Color_Card_Count;

	int nSrcLeft = nCol * nCardWidth + 5;
	int nSrcTop = nRow * nCardHeight + 5;

	CRect rcDst(m_nCurPosX, m_nCurPosY, m_nCurPosX + SmallCard_Width, m_nCurPosY + SmallCard_Height);
	CRect rcSrc(nSrcLeft, nSrcTop, nSrcLeft + SmallCard_Width, nSrcTop + SmallCard_Height);

	g_imgCard.DrawPart(pDC->m_hDC, rcDst, rcSrc);
}
